package com.shangyueshang.controller.supply;

import com.shangyueshang.model.FreightForwarder;
import com.shangyueshang.request.FreightDTO;
import com.shangyueshang.request.PageReq;
import com.shangyueshang.response.HttpResult;
import com.shangyueshang.response.PageResult;
import com.shangyueshang.service.FreightForwarderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2022/2/18 18:01
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/freight")
public class FreightController {

    @Resource
    private FreightForwarderService freightForwarderService;

    /**
     * 分页查询
     *
     * @param pageReq
     * @return
     */
    @PostMapping("/findPage")
    @PreAuthorize("hasAuthority('supply:freight:view')")
    public HttpResult<PageResult<FreightForwarder>> findPage(@RequestBody PageReq pageReq) {
        return HttpResult.ok(freightForwarderService.findPage(pageReq));
    }

    /**
     * 保存
     *
     * @param request
     * @return
     */
    @PostMapping("/save")
    @PreAuthorize("hasAuthority('supply:freight:add') and hasAuthority('supply:freight:edit')")
    public HttpResult<Boolean> save(@Valid @RequestBody FreightDTO request) {
        return freightForwarderService.saveUpdate(request);
    }

}
